package com.xej.seat.vo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.apache.ibatis.type.Alias;

import com.xej.seat.model.SeatingType;
import com.xej.seat.util.DoubleUtil;

/**
 * @author lisheng
 */
@Alias("seat")
public class Seat implements Comparable<Seat>, Serializable {

	private static final long serialVersionUID = -6282060529383889405L;
	private int sid;
	private String hallId; //会场ID
	private int srow;
	private int scol;
	private int cusId; //人员
	private int ruleId;
	private SeatingType seatingType; //排座类型
	private Date createTime;
	private List<Tag> tags; //标签
	private double sweight;
	private String org; //机构
	private String title; //职称
	private String name; //人员名称
	private int row;
	private int column;
	private int seatNo;
	public Seat() {
		super();
	}
	
	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public int getColumn() {
		return column;
	}

	public void setColumn(int column) {
		this.column = column;
	}

	public int getSeatNo() {
		return seatNo;
	}

	public void setSeatNo(int seatNo) {
		this.seatNo = seatNo;
	}

	public Seat(String hallId, int srow, int scol) {
		super();
		this.hallId = hallId;
		this.srow = srow;
		this.scol = scol;
	}
	
	@Override
	public int compareTo(Seat otherSeat) {
		BigDecimal thisWeight = BigDecimal.valueOf(this.getSweight());
		BigDecimal otherWeight = BigDecimal.valueOf(otherSeat.getSweight());
		return otherWeight.compareTo(thisWeight);
	}

	/**
	 * set所有座位的权重
	 * @param row 总行数+1
	 * @param col 总列数
	 */
	public void setWeight(int totalRow, int rowCol) {
		/*// 行的权重
		double rowHeight = row - this.getSrow();
		// 列的权重
		double colHeight = col - Math.abs(DoubleUtil.div(Double.valueOf(col + 1), Double.valueOf(2)) - this.getScol());
		// 每个座位的权重
		this.setSweight(DoubleUtil.mul(rowHeight, colHeight));*/
		
		//行 权重
		double rowWeight = DoubleUtil.mul((totalRow - this.getSrow()), totalRow);
		//列  权重
		double colWeight = rowCol - Math.abs(DoubleUtil.div(Double.valueOf(rowCol + 1), Double.valueOf(2)) - this.getScol());
		this.setSweight(DoubleUtil.add(rowWeight, colWeight));
	}
	public int getSid() {
		return sid;
	}

	public void setSid(int sid) {
		this.sid = sid;
	}

	public String getHallId() {
		return hallId;
	}

	public void setHallId(String hallId) {
		this.hallId = hallId;
	}

	public int getSrow() {
		return srow;
	}

	public void setSrow(int srow) {
		this.srow = srow;
	}

	public int getScol() {
		return scol;
	}

	public void setScol(int scol) {
		this.scol = scol;
	}

	public int getCusId() {
		return cusId;
	}

	public void setCusId(int cusId) {
		this.cusId = cusId;
	}

	public int getRuleId() {
		return ruleId;
	}

	public void setRuleId(int ruleId) {
		this.ruleId = ruleId;
	}

	public SeatingType getSeatingType() {
		return seatingType;
	}

	public void setSeatingType(SeatingType seatingType) {
		this.seatingType = seatingType;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public List<Tag> getTags() {
		return tags;
	}

	public void setTags(List<Tag> tags) {
		this.tags = tags;
	}

	public double getSweight() {
		return sweight;
	}

	public void setSweight(double sweight) {
		this.sweight = sweight;
	}
	
	public String getOrg() {
		return org;
	}

	public void setOrg(String org) {
		this.org = org;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Seat [sid=");
		builder.append(sid);
		builder.append(", hallId=");
		builder.append(hallId);
		builder.append(", srow=");
		builder.append(srow);
		builder.append(", scol=");
		builder.append(scol);
		builder.append(", cusId=");
		builder.append(cusId);
		builder.append(", ruleId=");
		builder.append(ruleId);
		builder.append(", seatingType=");
		builder.append(seatingType);
		builder.append(", createTime=");
		builder.append(createTime);
		builder.append(", customer=");
		builder.append(", tags=");
		builder.append(tags);
		builder.append("]");
		return builder.toString();
	}
	
}
